package com.yuedou.api.service.product.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yuedou.api.dao.product.ProductAttrResultMapper;
import com.yuedou.api.entity.product.ProductAttrResult;
import com.yuedou.api.service.base.impl.BaseServiceImpl;
import com.yuedou.api.service.product.ProductAttrResultService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * 商品属性详情Service业务层处理
 *
 * @author ruoyi
 * @date 2021-08-11
 */
@Service
public class ProductAttrResultServiceImpl extends BaseServiceImpl<ProductAttrResultMapper, ProductAttrResult> implements ProductAttrResultService {

	/**
	 * 新增商品属性详情
	 * @param map map
	 * @param productId 商品id
	 */
	@Override
	public void insertProductAttrResult(Map<String, Object> map, Integer productId)
	{
		ProductAttrResult yxStoreProductAttrResult = new ProductAttrResult();
		yxStoreProductAttrResult.setProductId(productId);
		yxStoreProductAttrResult.setResult(JSONUtil.toJsonStr(map));
		yxStoreProductAttrResult.setChangeTime(new Date());

		long count = this.count(Wrappers.<ProductAttrResult>lambdaQuery()
			.eq(ProductAttrResult::getProductId,productId));
		if(count > 0) {
			this.remove(Wrappers.<ProductAttrResult>lambdaQuery()
				.eq(ProductAttrResult::getProductId,productId));
		}

		this.save(yxStoreProductAttrResult);
	}

}
